/* eslint-disable */
let id = 1000;
export default {
  data() {
    const generateData = _ => {
      const data = [];
      const alldata = ['立项','拆迁红线','场地移交','设计要点','测绘','土地挂牌','环评','勘察合同','施工图纸','土方工程','不动产权证','其他'];
      // data.push('征地拆迁','测绘','土地挂牌');
      for (let i = 0; i < alldata.length; i++) {
        data.push({
          key: i,
          label:alldata[i],
          // disabled: i % 4 === 0
        });
      }
      return data;
    };
    const data = [{
      id: 1,
      label: '征地拆迁',
      children: [{
        id: 4,
        label: '立项',
        children: [{
          id: 9,
          label: '立项前期'
        }, {
          id: 10,
          label: '立项后期'
        }]
      }]
    }, {
      id: 2,
      label: '土地挂牌',
      children: [{
        id: 5,
        label: '设计要点'
      }, {
        id: 6,
        label: '地价'
      }]
    }, {
      id: 3,
      label: '一级 3',
      children: [{
        id: 7,
        label: '二级 3-1'
      }, {
        id: 8,
        label: '二级 3-2'
      }]
    }];

    return {
      data: JSON.parse(JSON.stringify(data)),
      data: JSON.parse(JSON.stringify(data)),
      tempData: generateData(),
      value: [],
      // 模板数据
      companyData:[
        {
          id: '0001',
          name: '模板—土地',
          classify: '市政',
          type:'土地专项',
          time: '2020-03-20',
          person: '张三',

        },
        {
          id: '0002',
          name: '模板—土地',
          classify: '市政',
          type:'前期专项',
          time: '2020-03-13',
          person: '李四',

        },
        {
          id: '0003',
          name: '模板—拆迁',
          classify: '市政',
          type:'前期专项',
          time: '2020-03-11',
          person: '李四',
        }

      ],

      // '新增模板'弹窗
      dialogCompany:{
        title: '新增模板',
        status: false,
      },

      // ‘新增模板’表单数据
      companyFrom:{
        companyName: '',
        companyContact: '',
        companyTel: '',
        requisitionLimit: '',
        restrictedType: '',
        repairAssetType: '',
        restrictedType1:''
      },

      // '新增模板'表单验证
      companyRules: {
        companyName: [
          { required: true, message: '请输入模板名称', trigger: 'blur' },
        ],
        companyContact: [
          { required: true, message: '请输入创建人', trigger: 'blur' },
        ],
        companyTel: [
          { required: true, message: '请选择项目类别', trigger: 'blur' },
        ],
        requisitionLimit: [
          { required: true, message: '请选择专项', trigger: 'blur' },
        ],
        restrictedType: [
          { required: true, message: '请选择创建时间', trigger: 'blur' },
        ],
        restrictedType1: [
          { required: true, message: '请选择任务节点', trigger: 'blur' },
        ]
      },
      //'查看模板'弹窗
      looktemplate:{
        title: '查看模板',
        status: false,
      },
      //‘查看模板’表单数据
      lookForm:{
        id:'',
        name:'',
        classify:'',
        type:'',
        time:'',
        person:''
      },
      //'查看模板'数据
      lookdata:[
        {
          id:'0001',
          name: '模板—土地',
          classify: '市政',
          type:'土地专项',
          time: '2020-03-20',
          person: '张三',
          taskid:'0010',
          task:'征地拆迁'
        },
        {
        id:'0001',
        name: '模板—土地',
        classify: '市政',
        type:'土地专项',
        time: '2020-03-20',
        person: '张三',
        taskid:'0011',
        task:'测绘'},
        {
        id:'0001',
        name: '模板—土地',
        classify: '市政',
        type:'土地专项',
        time: '2020-03-20',
        person: '张三',
        taskid:'0110',
        task:'土地挂牌'},
        {
        id:'0001',
        name: '模板—土地',
        classify: '市政',
        type:'土地专项',
        time: '2020-03-20',
        person: '张三',
        taskid:'1010',
        task:'土地许可'},
        {
        id:'0001',
        name: '模板—土地',
        classify: '市政',
        type:'土地专项',
        time: '2020-03-20',
        person: '张三',
        taskid:'0111',
        task:'立项'},
        {
          id:'0001',
          name: '模板—土地',
          classify: '市政',
          type:'土地专项',
          time: '2020-03-20',
          person: '张三',
          taskid:'1011',
          task:'施工图纸'}
      ],
      //修改模板弹窗
      updatetemplate:{
        title: '修改模板',
        status: false,
      },
      // ‘修改模板’表单数据
      updateFrom:{
        companyName: '',
        companyContact: '',
        companyTel: '',
        requisitionLimit: '',
        restrictedType: '',
        repairAssetType: '',
      },
    }
  },
  mounted() {
  },
  methods: {
    // 新增模板弹窗
    dialogCompanyOpen(row){
      console.log(row.companyName)
      if(row.companyName == undefined){
        this.dialogCompany.title = '新增模板'
        this.resetCompany()
      }else{
        this.dialogCompany.title = '更新模板'
        this.companyFrom = row
      }
      this.dialogCompany.status = true
    },
    //修改模板弹窗
    updateTemplateOpen(row){
      console.log(row.companyName)
      if(row.companyName == undefined){
        this.dialogCompany.title = '修改模板'
        this.resetCompany()
      }else{
        this.dialogCompany.title = '修改模板'
        this.companyFrom = row
      }
      this.dialogCompany.status = true
    },
    //查看模板弹窗
    lookTemplateOpen(row){
      this.updateTemplateOpen(row)
      // console.log(row.id)
      // if(row.id == undefined){
      //   this.looktemplate.title = '查看模板'
      // }else{
      //   this.looktemplate.title = '查看模板'
      //   this.lookForm = row
      // }
      // this.looktemplate.status = true
    },

    handleChange(value, direction, movedKeys) {
      console.log(value, direction, movedKeys);
    },

    // 新增模板
    addCompany(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$message({
            type: 'success',
            message: '新增成功!'
          })
          this.dialogCompany.status = false
        } else {
          this.$message({
            type: 'warning',
            message: '请填写相关信息!'
          })
          return false;
        }
      });
    },

    // 重置新增模板表单
    resetCompany() {
      this.companyFrom = {
        companyName: '',
        companyContact: '',
        companyTel: '',
        requisitionLimit: '',
        restrictedType: '',
        repairAssetType: '',
      }
    },

    // 删除模板
    delCompany(row){
      this.$confirm('正在删除'+  row.companyName  +'公司, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    append(data) {
      const newChild = { id: id++, label: 'testtest', children: [] };
      if (!data.children) {
        this.$set(data, 'children', []);
      }
      data.children.push(newChild);
    },

    remove(node, data) {
      const parent = node.parent;
      const children = parent.data.children || parent.data;
      const index = children.findIndex(d => d.id === data.id);
      children.splice(index, 1);
    },

    renderContent(h, { node, data, store }) {
      return (
        <span class="custom-tree-node">
          <span>{node.label}</span>
          <span>&nbsp;&nbsp;
            <el-button type="text" on-click={ () => this.append(data) }>添加节点</el-button>
            <el-button type="text" on-click={ () => this.append(data) }>编辑节点</el-button>
            <el-button type="text" on-click={ () => this.remove(node, data) }>删除节点</el-button>
          </span>
        </span>);
    }

  }
}
